package com.yq.bootdemo.service.impl;

import com.yq.bootdemo.entity.CustomerEntity;
import com.yq.bootdemo.mapper.CustomerMapper;
import com.yq.bootdemo.mapper.RoomMapper;
import com.yq.bootdemo.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    CustomerMapper customerMapper;
    @Resource
    RoomMapper roomMapper;
    @Override
    public List<CustomerEntity> selectAll() {
        return customerMapper.selectAll();
    }

    @Override
    public boolean insertOne(String cName, String cNum, String cPhone, Integer rNum) {
        if (cName == null || cName == "" || cNum == null || cNum == "" || cPhone == null
                || cPhone == "" || rNum == null || rNum == 0 ) return false;

        return customerMapper.insertOne(cName,cNum,cPhone,rNum) != 0 && roomMapper.stay(rNum,1) != 0;
    }

    @Override
    public CustomerEntity selectOne(Integer id) {
        return customerMapper.selectOne(id);
    }

    @Override
    public boolean delOne(Integer id) {
        if(id == null || id == 0)return false;
        CustomerEntity customerEntity = selectOne(id);

        return customerMapper.delOne(id) != 0 && roomMapper.stay(customerEntity.getRoomEntity().getId(),0) != 0;
    }
}
